<script setup>
import tarbar from '@/layout/tarbar/tarbar.vue';
import navbar from '@/layout/header/navbar.vue';
import { ref } from 'vue';

const list = ref([]);
    const loading = ref(false);
    const finished = ref(false);
    

    const records = ref([]);

    const onLoad = () => {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          list.value.push(list.value.length + 1);
        }

        // 加载状态结束
        loading.value = false;

        // 数据全部加载完成
        if (list.value.length >= 40) {
          finished.value = true;
        }
      }, 1000);
    };
    // const onLoad = async () => {
    //     loading.value.push
    // };

</script>

<template>
<navbar></navbar>
<h1>test</h1>
<van-list
  v-model:loading="loading"
  :finished="finished"
  finished-text="没有更多了"
  @load="onLoad"
>
  <van-cell v-for="item in list" :key="item" :title="item">
    <template #="right">
        <van-button size="mini" type="primary" @click="onLoad">加载更多</van-button>
    </template>
  </van-cell>
</van-list>
<tarbar></tarbar>
</template>

<style>
</style>